--[[
 -- *名称:ddzcard
 -- *描述:斗地主扑克牌
 -- *版权:Copyright © 2016-2018 深圳市三只小熊科技有限公司 版权所有
 -- *作者:Administrator
 -- *创建日期:2017-11-07
 -- *修改日期:2017-11-07
 -- @return [description]
 ]]
local Card = require(basePath.."domain/card");

local DdzCard = pokercore.class(Card,false);
---
 -- 构造方法
 -- @DateTime 2017-11-07
 -- @param    cardShape [description]
 -- @param    number [description]
 -- @param    isLaizi [description]
 -- @return    [description]
 --
function DdzCard:ctor( cardShape, number, isLaizi ,value, laiziNumber)
	-- 是否癞子
	self.isLaizi = isLaizi;
	-- 癞子类型 默认0地癞子，1天癞子
	self.laiziType = 0;
	
	-- 癞子点数，默认为0为不赋值，此时读取number，可变
	self.laiziNumber = laiziNumber or 0;

	DdzCard.super.ctor(self, cardShape, number,value);

--癞子直接赋值了 ？ 会导致接下去癞子判定错误，暂时屏蔽
	--print("DdzCard.super.ctor");
	--if self:isLazi() and value then
	--	self:changeCard(value);
	--end

end

function DdzCard:dtor(  )

end

function DdzCard:revalue(  )
	----print("DdzCard:revalue");
	if self:isLazi() and self.laiziNumber ~= 0 then -- 有癞子点数的时候重新定义value
		----print("laizi number->",self.laiziNumber)
		if self.laiziNumber == 1 then 
			self:setValue(PokerGameConstant.NUMBER_1_VALUE);
		elseif self.laiziNumber == 2 then 
			self:setValue(PokerGameConstant.NUMBER_2_VALUE);
		else 
			self:setValue(self.laiziNumber or 0);
		end
		return self;
	else 
		if self:getCardShape() == CardShape.RED_JOKER then -- 大王
			self:setNumber(PokerGameConstant.RED_JOKER_SHAPE_NUM);
			self:setValue(PokerGameConstant.RED_JOKER_SHAPE_VALUE);
		elseif self:getCardShape() == CardShape.BLACK_JOKER then -- 小王
			self:setNumber(PokerGameConstant.BLACK_JOKER_SHAPE_NUM);
			self:setValue(PokerGameConstant.BLACK_JOKER_SHAPE_VALUE);
		else 
			if self:getNumber() == 1 then 
				self:setValue(PokerGameConstant.NUMBER_1_VALUE);
			elseif self:getNumber() == 2 then 
				self:setValue(PokerGameConstant.NUMBER_2_VALUE);
			else 
				self:setValue(self:getNumber());
			end
		end
		return self;
	end
end

---
 -- 排序 null，牌，癞子
 -- @DateTime 2017-11-07
 -- @param    o Card
 -- @return    [description]
 --
function DdzCard:compareWithShapeTo( o )
	if o == nil then 
		return 1;
	else 
		----print("self.number->",self.number)
		----print("other.number->",o.number)
		local ddzO = o;
		if self:hasNotChanged() and ddzO:hasNotChanged() then 
			return self:compareWithShapeLaiziTo(ddzO);
		elseif self:hasNotChanged() then 
		--	--print("self,hasNotChanged");
			return 1;
		elseif ddzO:hasNotChanged() then 
		--	--print("other,hasNotChanged");
			return -1;
		else 
		--	--print("DdzCard:compareWithShapeTo")
			return self:compareWithShapeLaiziTo(ddzO);
		end
	end
end
---
 -- 带花色癞子的比较，用于排序 <br>
 -- 黑红梅方 value 小的在前面
 -- 癞子还在黑桃前
 -- @DateTime 2017-11-07
 -- @param    o Card
 -- @return   int
 --
function DdzCard:compareWithShapeLaiziTo( o ) 
	if o == nil then 
		return 1;
	else 

		local weight_c = self:getValue() - o:getValue();
		----print("weight_c",weight_c);
		if weight_c == 0 then 
			local ddzO = o;
			if self:isLazi() and ddzO:isLazi() then 
				if o:getCardShape() ==  nil then 
					return 1;
				else 
					return self:getCardShape():getShape() - o:getCardShape():getShape();
				end
			elseif self:isLazi() then 
				----print("###############")
				return 1;
			elseif ddzO:isLazi() then 
				return -1;
			else 
				if o:getCardShape() == nil then 
					return 1;
				else 
					return self:getCardShape():getShape() - o:getCardShape():getShape();
				end
			end
		else 
			return weight_c;
		end
	end
end
---
 -- 是癞子牌，并且已经改变值
 -- @return boolean
function DdzCard:hasNotChanged() 
	return self:isLazi() and self.laiziNumber == 0;
end

function DdzCard:hasChanged()
	return self:isLazi() and self.laiziNumber > 0;
end

---
 -- 改变癞子牌
 -- @param 
function DdzCard:changeCard(valueOrNumber) -- 有癞子点数的时候重新定义value
	if self:isLazi() then 
		--print("!!!!!!!!!!!!!!!!!!!!!!!");
		self.laiziNumber = DdzTypeUtil.getNumberByValue(valueOrNumber);
		self:revalue();
	end
end
---
 -- 
function DdzCard:toString() 
	if self:isLazi() then 
		return DdzCard.super.toString() + "*" + self.laiziNumber;
	else 
		return DdzCard.super.toString();
	end
end

function DdzCard:hasLaizi()
	return self:isLazi();
end

function DdzCard:isLazi()
	return self:getCardShape() == CardShape.RED_JOKER or self:getCardShape() == CardShape.BLACK_JOKER;
end

function DdzCard:getLaiziType()
	return self.laiziType;
end

function DdzCard:setLaiziType(laiziType)
	self.laiziType = laiziType;
end

function DdzCard:setLaizi(isLaizi)
	self.isLaizi = isLaizi;
end

function DdzCard:getLaiziNumber()
	return self.laiziNumber;
end

function DdzCard:setLaiziNumber()
	self.laiziNumber = laiziNumber;
end

return DdzCard;


